package leetcode;

import java.util.HashMap;

public class Test1512 {
    public int numIdenticalPairs(int[] nums) {
        HashMap<Integer,Integer> dic=new HashMap<Integer, Integer>();
        int count=0;
        for(int i=0;i<nums.length;i++){
            if(dic.containsKey(nums[i])==false){
                dic.put(nums[i],1);
            }
            else{
                dic.put(nums[i],dic.get(nums[i])+1);
            }
        }
        for(int i=0;i<nums.length;i++){
            if(dic.containsKey(nums[i]) && dic.get(nums[i]) >1){
                //System.out.println(dic.get(nums[i]));
                //System.out.println(count);
                count+= dic.get(nums[i])*(dic.get(nums[i])-1)/2;
                //System.out.println(count);
                dic.remove(nums[i]);
            }
        }
        return count;
    }
}
